<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="80" prop="userId" />
      <el-table-column label="昵称" prop="nickname" align="center" />
      <el-table-column label="用户名" width="600" align="center" prop="username" />
      <el-table-column label="身份" width="110" align="center" prop="identity" />
      <el-table-column
        fixed="right"
        label="操作"
        width="100"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="view(scope.row)">查看</el-button>
          <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      search: {
        id: 0,
        name: '',
        pageSize: 10,
        pageCurrent: 1
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    view(row) {
      console.log(row)
    },
    edit(row) {
      console.log(row)
    },
    fetchData() {
      this.listLoading = true
      getList(this.search).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    getIdentity(i) {
      switch (i) {
        case 1:
          return '管理员'
        case 2:
          return '教师'
        case 3:
          return '学生'
      }
    }
  }
}
</script>
